package com.kaifamiao.controller;

import com.kaifamiao.pojo.AdminUser;
import com.kaifamiao.service.IAdminService;
import com.kaifamiao.service.imp.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    IAdminService iAdminService = null;

    @RequestMapping("/login")
    public String admin() {
        return "admin_user/index";
    }

    @RequestMapping("/login.do")
    public String login(AdminUser admin, Model model) {
        AdminUser adminUser = iAdminService.findByUserName(admin.getAdmin_username());
        model.addAttribute("admin_username",admin.getAdmin_username());
        if (adminUser != null) {
            if (adminUser.getAdmin_password().equals(admin.getAdmin_password())) {
                return "Patientinfohtml/index";
            }else {
                model.addAttribute("adminPassworderr", "密码错误");
                return "admin_user/index";
            }
        } else {
            model.addAttribute("adminUserNameerr", "该管理员不存在");
            return "admin_user/index";
        }
    }
}
